package service;


import java.util.List;


import common.DButil;
import vo.ReaderBean;
import vo.UserBean;

public class ReaderSerivice {
	public  List<Object> getAll(){
		String sql="select r_id,r_name ,r_tel,r_money from reader";
		DButil db = DButil.getInstance();
		List<Object> list=db.excuteQuery(sql,ReaderBean.class );
		db.close();
		return list;
	}
	public  List<Object> get(String rid,String rname,String rtel){
		String sql="select r_id,r_name ,r_tel,r_money from reader where r_id like '%"+rid+"%' and r_name like '%"+rname+"%' and r_tel like '%"+rtel+"%'" ;
			
		DButil db = DButil.getInstance();
		List<Object> list=db.excuteQuery(sql,ReaderBean.class );
		db.close();
		return list;
	}
	public  void insert(String rname,String rcard,String raddr,String rtel,double rmoney,String rtime,String uuser){
		String sql="insert into reader(r_name,r_card,r_addr,r_tel,r_money,r_time,u_user) values('"+rname+"','"+rcard+"','"+raddr+"','"+rtel+"',"+rmoney+",'"+rtime+"','"+uuser+"')";
		
		DButil db = DButil.getInstance();
		db.excuteUpdate(sql);
		db.close();
	}
	
	public  List<Object> get(int  rid){
		String sql="select r_id,r_name ,r_card,r_addr,r_tel,r_money,r_time,u_user from reader where r_id ="+rid+"" ;
		DButil db = DButil.getInstance();
		List<Object> list=db.excuteQuery(sql,ReaderBean.class );
		db.close();
		return list;
	}
	public  void update(int rid,String rname,String rcard,String raddr,String rtel,double rmoney,String rtime,String uuser){
		String sql="update reader set r_name='"+rname+"',r_card='"+rcard+"',r_addr='"+raddr+"',r_tel='"+rtel+"',r_money="+rmoney+",r_time='"+rtime+"',u_user='"+uuser+"' where r_id="+rid+"";
		
		DButil db = DButil.getInstance();
		db.excuteUpdate(sql);
		db.close();
	}
	public  void update(String rid,double money){
		 String upsql="update reader set r_money=r_money+'"+money+"' where r_id='"+rid+"'";
			DButil db = DButil.getInstance();
			
		db.excuteUpdate(upsql);
		db.close();
	}
	public  void dprice(int rid,double money){
		 String upsql="update reader set r_money=r_money-'"+money+"' where r_id='"+rid+"'";
			DButil db = DButil.getInstance();
			
		db.excuteUpdate(upsql);
		db.close();
	}
}
